package com.carlinfo.myjdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class BantchMain
{
	public static void main(String[] args)
	{
		DbUtil dbUtil = new DbUtil();
		Connection conn = dbUtil.getConnection();
		
		PreparedStatement pst = null;
		long time = System.currentTimeMillis();
		try
		{	
			
			for(int i = 0;i<1000;i++)
			{
				String sql ="INSERT INTO `mydata`(`name`) VALUES (?)";
				pst = conn.prepareStatement(sql);
				pst.setObject(1, "王天亮");
				pst.addBatch();
				if(i%100==0) 
				{
					int[] r = pst.executeBatch();
					System.out.println("提交了一次:"+i);
				}
			}	
			long time1 = System.currentTimeMillis();
			System.out.println("时间"+(time1-time));
		} catch (SQLException e)
		{
			e.printStackTrace();
		} finally {
			dbUtil.closeAll(pst, conn, null);
		}
	}
}
